<template>
	<view class="">
		<dsl-navbar title="地址管理" isBack bgTopImg='white'></dsl-navbar>
		<view class="address padding" v-for="(item,index) in addressList" :key='index'>
			<view class="address_body padding-bottom solid-bottom">
				<view class="rowsb">
					<view class="title">{{item.contacts}}</view>
					<view class="phone">{{item.contact_number}}</view>
				</view>
				<view class="address">{{item.address}} {{item.detailed_address}}</view>
			</view>
			<view class="rowsb align-center padding-top">
				<view class="align-center" v-if="item.switch ==1">
					<image src="/static/address/xuanzhong.png"></image>
					<text class="select margin-left">默认地址</text>
				</view>
				<view v-else></view>
				<view class="align-center">
					<view class="align-center" @click="settingAddress(item)">
						<image src="/static/address/icon_bianji.png"></image>
						<text class="setting margin-left">编辑</text>
					</view>
					<view class="margin-left align-center" @click="detailAddress(item)">
						<image src="/static/address/icon_shanchu.png"></image>
						<text class="delete margin-left">删除</text>
					</view>
				</view>
			</view>
		</view>
		<view class="rowsc" @click="upAddress()">
			<view class="address_submit">
				新增地址
			</view>
		</view>
	</view>
</template>

<script>
	import{get_address,detail_address} from '@/common/path.js'
	export default {
		data() {
			return{
				addressList:[]
			}
		},
		onShow() {
			this.getAddress()
		},
		methods:{
			upAddress(){
				uni.navigateTo({
					url:'setting'
				})
			},
			//收货地址
			getAddress(){
				console.log('[成功]');
				this.Http.POST(get_address,{})
				.then((res)=>{
					console.log('[收货地址]',res);
					if(res.code ==1){
						this.addressList  = res.data
					}else{
						this.addressList  = []
					}
				})
				.catch((err)=>{
					console.log('[失败]',err);
				})
			},
			//删除
			detailAddress(event){
				let data ={
					id:event.id
				}
				this.Http.POST(detail_address,data)
				.then((res)=>{
					console.log('[收货地址]',res);
					if(res.code ==1){
						this.getAddress()
						this.$tools.showToast2(res.msg)
					}else{
						this.$tools.showToast(res.msg)
					}
				})
			},
			//编辑
			settingAddress(event){
				uni.navigateTo({
					url:'setting?id='+event.id
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #F5F5F5;
	}

	.address {
		width: 750rpx;
		opacity: 1;
		background-color: white;
		margin-top: 20rpx;

		.address_body {
			.title {
				width: 340rpx;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #3C3C3C;
				opacity: 1;
			}

			.phone {
				font-size: 22rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #3C3C3C;
				opacity: 1;
			}

			.address {
				width: 654rpx;
				font-size: 22rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #3C3C3C;
				opacity: 1;
			}
		}

		.select {
			font-size: 20rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #FF6B2B;
			opacity: 1;
		}

		.setting {
			font-size: 20rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #3C3C3C;
			opacity: 1;
		}

		image {
			width: 24rpx;
			height: 24rpx;
		}

		.delete {
			font-size: 20rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #3C3C3C;
			opacity: 1;
		}
	}

	.address_submit {
		width: 658rpx;
		height: 90rpx;
		background: linear-gradient(180deg, #FF6B2B 0%, #FF8A19 100%);
		border-radius: 99rpx;
		opacity: 1;
		line-height: 90rpx;
		text-align: center;
		color: white;
		position: fixed;
		z-index: 999;
		bottom: 60rpx;
	}
</style>
